package com.example.wechat.csdnandroid.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.wechat.csdnandroid.R;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button mBtAmClick1;
    private Button mBtAmClick2;
    private Button mBtAmClick3;
    private TextView mTvAmFrom;
    private Button mBtAmService;
    private Button mBtAmForegroundservice;
    private Button mBtAmCpa;
    private Button mBtAmListView;
    private Button mBtAmListView2;
    private Button mBtAmRv;
    private Button mBtAmVp;

    //        ctrl+alt+f    +enter


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //ctrl+shift+l格式化代码
//        alt+insert
        setContentView(R.layout.activity_main);
        //alt＋ｃｔｒｌ＋ｓ来打开设置

//
        initView();
        initData();
//        String form = getIntent().getStringExtra("form");
//        if ("LifeCycleActivity".equals(form)) {
////            Toast.makeText(this, "我是从LifeCycleActivity页面来的数据", Toast.LENGTH_SHORT).show();
//            mTvAmFrom.setText("form:LifeCycleActivity");
//            mTvAmFrom.setOnClickListener(this);
//        } else {
//            startActivity(new Intent(this, PermissionActvity.class));
//            finish();
//        }

    }

    private void initData() {
        mBtAmClick1.setOnClickListener(this);
        mBtAmClick2.setOnClickListener(this);
        mBtAmClick3.setOnClickListener(this);
        mBtAmService.setOnClickListener(this);
        mBtAmForegroundservice.setOnClickListener(this);
        mBtAmCpa.setOnClickListener(this);
        mBtAmListView.setOnClickListener(this);
        mBtAmRv.setOnClickListener(this);
        mBtAmListView2.setOnClickListener(this);
        mBtAmVp.setOnClickListener(this);
    }


    private void initView() {
        mBtAmClick1 = (Button) findViewById(R.id.bt_am_click1);
        mBtAmClick2 = (Button) findViewById(R.id.bt_am_click2);
        mBtAmClick3 = (Button) findViewById(R.id.bt_am_click3);
        mTvAmFrom = (TextView) findViewById(R.id.tv_am_from);
        mBtAmService = (Button) findViewById(R.id.bt_am_service);
        mBtAmForegroundservice = (Button) findViewById(R.id.bt_am_foregroundservice);
        mBtAmCpa = (Button) findViewById(R.id.bt_am_cpa);
        mBtAmListView = (Button) findViewById(R.id.bt_am_listview);
        mBtAmListView2 = (Button) findViewById(R.id.bt_am_listview2);
        mBtAmRv = (Button) findViewById(R.id.bt_am_rv);
        mBtAmVp = (Button) findViewById(R.id.bt_am_vp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_am_click1:
                Toast.makeText(MainActivity.this, "你好啊1", Toast.LENGTH_SHORT).show();
                break;
            case R.id.bt_am_click2:
                Toast.makeText(MainActivity.this, "你好啊2", Toast.LENGTH_SHORT).show();
                break;
            case R.id.bt_am_click3:
                Toast.makeText(MainActivity.this, "你好啊3", Toast.LENGTH_SHORT).show();
                break;
            case R.id.bt_am_service:
                startActivity(new Intent(MainActivity.this, StartStopSeriviceActivity.class));
                break;
            case R.id.bt_am_cpa:
                startActivity(new Intent(MainActivity.this, ContentProviderAvtivity.class));
                break;
            case R.id.bt_am_foregroundservice:
                startActivity(new Intent(MainActivity.this, ForegroundActivity.class));
                break;
            case R.id.bt_am_listview:
                startActivity(new Intent(MainActivity.this, ListViewActivity.class));
                break;
            case R.id.bt_am_listview2:
                startActivity(new Intent(MainActivity.this, ListView2Activity.class));
                break;
            case R.id.bt_am_rv:
                startActivity(new Intent(MainActivity.this, RecyclerViewActivity.class));
                break;
                case R.id.bt_am_vp:
                startActivity(new Intent(MainActivity.this, ViewPagerActivity.class));
                break;
            case R.id.tv_am_from:
//                 返回
                Intent i = new Intent();
                i.putExtra("form", "MainActivity");
                setResult(RESULT_OK, i);
                finish();
                break;
        }
    }
}
